<template>
  <div>
    <img src="../assets/docx.jpg"  alt="word" class="image" @click="handleGoEdit">
    <div style="padding: 20px;">
      <span>{{teamArticleItem.name}}</span>
      <div class="bottom clearfix">
        <time class="time">{{teamArticleItem.edit_dt}}</time>
        <br>
        <!-- 
            <el-tooltip class="item" effect="dark" content="收藏" placement="bottom-start" v-if="!teamArticleItem.is_starred">
          <el-button type="warning" plain icon="el-icon-star-off" circle @click="handleTeamArticle" size="mini"></el-button>
        </el-tooltip>
        <el-tooltip class="item" effect="dark" content="取消收藏" placement="bottom-start" v-else>
          <el-button type="warning" icon="el-icon-star-off" circle @click="handleTeamArticle" size="mini"></el-button>
        </el-tooltip>
         -->
        
      </div>
    </div>
  </div>
</template>

<script>
import {mapActions,mapState} from 'vuex'
import {reqLikeornotArticle,reqGetAuth} from '../api'
export default {
  name: 'TeamArticle',
  data:function (){
    return{
      currentDate: new Date(),
     
    }
  },
  props:{
    teamArticleItem:Object
  },
  computed:{
    ...mapState(['userInfo','likeList','onedit','checkTeamInfo'])
  },
  mounted () {
 //  this.recordLikeList()
    console.log(this.checkTeamInfo)
    this.recordTeamInfo(this.checkTeamInfo)
    if(this.checkTeamInfo){
      console.log(this.checkTeamInfo)
      this.getTeamArticle(this.checkTeamInfo)
    }
  },
  methods:{
    ...mapActions(['recordTeamInfo','getTeamArticle','getLikeList','getGarbageList','getCreateList','getCurrentList','recordLikeList','recordOnEdit']),
    handleTeamArticle(){
      this.teamArticleItem.islike=!this.teamArticleItem.islike
      if(this.teamArticleItem.islike){//收藏
        //调用收藏接口，修改数据库收藏列表
        console.log(this.teamArticleItem)
        const result=reqLikeornotArticle(this.userInfo.userid,this.teamArticleItem.articleid,true)
        //更新state中的收藏列表
        setTimeout(() => {
       //   this.getLikeList()
          //更新回收站列表
          this.getGarbageList()
          //更新创建列表
          this.getCreateList()
          //更新浏览列表
          this.getCurrentList()
        },500)
        console.log(this.teamArticleItem)
      }
      else{//取消收藏
        //调用收藏接口，修改数据库收藏列表
        const result=reqLikeornotArticle(this.userInfo.userid,this.teamArticleItem.articleid,false)
        //更新state中的收藏列表
        setTimeout(() => {
         // this.getLikeList();
          //更新回收站列表
          this.getGarbageList()
          //更新创建列表
          this.getCreateList()
          //更新浏览列表
          this.getCurrentList()
        },500)
        console.log(this.teamArticleItem)
      }
    },
    async handleGoEdit(){
        console.log('rrrr')
        console.log(this.checkTeamInfo)
        console.log(this.checkTeamInfo.tid)
        const result=await reqGetAuth(this.userInfo.userid,this.checkTeamInfo.tid)
        console.log('!!!')
        console.log(result)
        console.log(result.authLevel)
        
        if(result.authLevel===0){
          
          alert('您不具有读取文件的权限')
          return
        }
        else{
          this.recordOnEdit(this.teamArticleItem.id)
          console.log('963258741')
           console.log(this.onedit)
          this.$router.push('/teamedit')
          
     
        }
    }
  }
}
</script>

<style >
.time {
  font-size: 13px;
  color: #999;
}

.bottom {
  margin-top: 13px;
  line-height: 12px;
}

.button {
  padding: 0;
  float: right;
}

.image {
  width: 100%;
  display: block;
  margin-top: 8px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both
}
.box {
  width: 400px;
}
.top {
  text-align: center;
}

.left {
  float: left;
  width: 60px;
}

.right {
  float: right;
  width: 60px;
}

.bottom {
  clear: both;
  text-align: center;
}

</style>
